//获取堆叠条形图的数据
import { BidirectionalBarChartList } from '@/services/BidirectionalBarChart';
import { useEffect, useState } from 'react';

type BidirectionalBarChartItem = {
  title: string;
  measures: number[];
};

const useBidirectionalBarChart = (): BidirectionalBarChartItem[] => {
  const [bidirectionalBarChartList, setbidirectionalBarChartList] = useState<
    BidirectionalBarChartItem[]
  >([]);
  useEffect(() => {
    const fetchData = async () => {
      try {
        const res = await BidirectionalBarChartList();
        if (res.success) {
          console.log(
            'bidirectionalBarChartList:',
            res.data.BidirectionalBarChartData,
          );
          setbidirectionalBarChartList(res.data.BidirectionalBarChartData);
        }
      } catch (error) {
        console.error('Error fetching bidirectionalBarChartList data:', error);
      }
    };

    fetchData();
  }, []);

  return bidirectionalBarChartList;
};

export default useBidirectionalBarChart;
